"""Isolated contact problem (Test 6 and 7) from Toro Chapter 10""" 

from hogs.grids import grid1d as grid
from hogs.solvers.euler1d import EESolver
from hogs.solvers.flux.euler.eulerian_flux import GodunovFluxEulerian, \
     EulerLxf, WAFFluxEulerian

from hogs.solvers.time_step_functions import EulerEquationsTimeStep
from hogs.solvers.primitive_variable_functions import EEPrimitiveVariable

import numpy

# parameters
gamma = 1.4

# create and initialize the grid
g = grid.Grid1D()
g.initialize(xlow=0, xhigh=1.2, dx=0.0012, nb=2, nvar=3)

# construct the solver
solver = EESolver(gamma=1.4, tf=0.15, nvar=3, grid=g)

# set the flux function
#solver.flux_function = flux.GodunovFluxEulerian(gamma=1.4)
solver.flux_function = WAFFluxEulerian(gamma=1.4)
#solver.flux_function = EulerLxf()

# set the grid for the flux function
solver.flux_function.set_grid( solver.grid )

# set the time step function
solver.time_step_function = EulerEquationsTimeStep(grid=solver.grid)

# primitive variable function
solver.primitive_variable_function = EEPrimitiveVariable(gamma=gamma,
                                                         grid=solver.grid)

# process command line 
solver.setup()

# set the variables
grid = solver.grid

# cell centers
x = grid.xc
q = grid.q

# initial data for the shock tube problem
rhol = 1.4; rhor = 1.0
pl = 1.0; pr = 1.0
ul, ur = 0.1, 0.1

el = pl/(0.4 * rhol)
er = pr/(0.4 * rhor)

for i, j in enumerate(x):
    if j < 0.0:

        q[0,i] = rhol
        q[1,i] = rhol*ul

        q[2,i] = rhol * (0.5 * ul**2 + el)

    else:

        q[0,i] = rhor
        q[1,i] = rhor*ur

        q[2,i] = rhor * (0.5 * ur**2 + er)

solver.solve()
